package com.ruoyi.campus.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.campus.mapper.MyApplyMapper;
import com.ruoyi.campus.domain.MyApply;
import com.ruoyi.campus.service.IMyApplyService;

/**
 * 悬赏榜领取申请Service业务层处理
 *
 * @author zht
 * @date 2022-02-12
 */
@Service
public class MyApplyServiceImpl implements IMyApplyService
{
    @Autowired
    private MyApplyMapper myApplyMapper;

    /**
     * 查询悬赏榜领取申请
     *
     * @param applyId 悬赏榜领取申请主键
     * @return 悬赏榜领取申请
     */
    @Override
    public MyApply selectMyApplyByApplyId(String applyId)
    {
        return myApplyMapper.selectMyApplyByApplyId(applyId);
    }

    /**
     * 查询悬赏榜领取申请列表
     *
     * @param myApply 悬赏榜领取申请
     * @return 悬赏榜领取申请
     */
    @Override
    public List<MyApply> selectMyApplyList(MyApply myApply)
    {
        return myApplyMapper.selectMyApplyList(myApply);
    }

    /**
     * 新增悬赏榜领取申请
     *
     * @param myApply 悬赏榜领取申请
     * @return 结果
     */
    @Override
    public int insertMyApply(MyApply myApply)
    {
        myApply.setApplyTime(DateUtils.getNowDate());
        return myApplyMapper.insertMyApply(myApply);
    }

    /**
     * 修改悬赏榜领取申请
     *
     * @param myApply 悬赏榜领取申请
     * @return 结果
     */
    @Override
    public int updateMyApply(MyApply myApply)
    {
        return myApplyMapper.updateMyApply(myApply);
    }

    /**
     * 批量删除悬赏榜领取申请
     *
     * @param applyIds 需要删除的悬赏榜领取申请主键
     * @return 结果
     */
    @Override
    public int deleteMyApplyByApplyIds(String[] applyIds)
    {
        return myApplyMapper.deleteMyApplyByApplyIds(applyIds);
    }

    /**
     * 删除悬赏榜领取申请信息
     *
     * @param applyId 悬赏榜领取申请主键
     * @return 结果
     */
    @Override
    public int deleteMyApplyByApplyId(String applyId)
    {
        return myApplyMapper.deleteMyApplyByApplyId(applyId);
    }

    /**
     * 获取个人申请的悬赏榜Id
     * @param userId 用户Id
     * @return 结果
     */
    @Override
    public List<String> getMyApplyOfferId(String userId) {
        return myApplyMapper.getMyApplyOfferId(userId);
    }

    /**
     * 获取个人要审核的悬赏榜信息
     * @param iuserId 当前用户ID
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> getMyAuditOffer(String iuserId) {
        return myApplyMapper.getMyAuditOffer(iuserId);
    }

    /**
     * 同意通过申请
     * @param offerId 悬赏榜ID
     * @param ruserId 提供用户ID
     * @return 结果
     */
    @Override
    public int agreeApply(String offerId, String ruserId) {
        if (myApplyMapper.updateOfferRUser(offerId,ruserId) > 0){
            myApplyMapper.deleteMyapplyByOfferId(offerId,ruserId);
            return 1;
        }else{
            return 0;
        }
    }

    /**
     * 获取我申请的悬赏榜信息
     * @param userId 用户ID
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> getMyApplyOffer(String userId) {
        return myApplyMapper.getMyApplyOffer(userId);
    }
}
